﻿
class Date {
  private int year, month, date, hours, minutes, seconds;

  public Date() {
    setTime( currentTimeMillis() );
  }

  public Date( int year, int month, int date ) {
    this( year, month, date, 0, 0, 0 );
  }

  public Date( int year, int month, int date, int hours, int minutes, int seconds ) {
    this.year = year;
    this.month = month;
    this.date = date;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;
  }

  /*
   * get methods
   */
  public int getYear() {
    return year;
  }

  public int getMonth() {
    return month;
  }

  public int getDate() {
    return date;
  }

  public int getHours() {
    return hours;
  }

  public int getMinutes() {
    return minutes;
  }

  public int getSeconds() {
    return seconds;
  }

  native public long getTime();

  /*
   * set methods
   */
  public void setYear( int year ) {
    this.year = year;
  }

  public void setMonth( int month ) {
    this.month = month;
  }

  public void setDate( int date ) {
    this.date = date;
  }

  public void setHours( int hours ) {
    this.hours = hours;
  }

  public void setMinutes( int minutes ) {
    this.minutes = minutes;
  }

  public void setSeconds( int seconds ) {
    this.seconds = seconds;
  }

  native public void setTime( long millis );

  /*
   * arithmetic methods
   */
  //native public void add( Date other );

  // PRE: other <= this
  //native public void sub( Date other );

  /*
   * comparison methods
   */
  public boolean equals( Object obj ) {
    if ( obj instanceof Date ) {
      Date other = (Date) obj;
      return this.getTime() == other.getTime();
    } else
      return super.equals( obj );
  }

  public int compareTo( Date other ) {
    return sign( this.getTime() - other.getTime() );
  }

  // PRE: 0 <= value && value <= 99
  private String twoDigits( int value ) {
    if ( value < 10 )
      return "0" + value;
    else
      return "" + value;
  }

  public String toString() {
    return twoDigits( hours ) + ":" + twoDigits( minutes ) + ":" + twoDigits( seconds ) +
           " - " +
           date + "/" + month + "-" + year;
  }
}
